package appnode;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.servlet.http.*;
import javax.servlet.*;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import appnode.Node;
import appnode.Linktools;
import appnode.SearchNode;
import appnode.PMF;

public class TableOfmsg extends HttpServlet {
	
	 public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
			
		String nodename = req.getParameter("nodename");
		
		// user
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		
		Node node = SearchNode.getByName(nodename);
		
		if (user!=null) {
			if ((SearchNode.validatePage(node.getNodename(),user.getNickname()).equals("yes"))) {
				String url = "/tablmsg.jsp?nodename="+nodename;
				ServletContext sc = getServletContext();
				RequestDispatcher rd = sc.getRequestDispatcher(url);			
				rd.forward(req, resp);
			}
			else {
				resp.setContentType("text/html");
				resp.getWriter().println("<html>");
				resp.getWriter().println("permission denied");
				resp.getWriter().println("</html>");
			}	
		
		}
		else {
			String url = "/";
			ServletContext sc = getServletContext();
			RequestDispatcher rd = sc.getRequestDispatcher(url);			
			rd.forward(req, resp);
		}
		
		
		}
}